﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ScreenConnection
{
    /// <summary>
    /// Logique d'interaction pour Splashscreen.xaml
    /// </summary>
    public partial class Splashscreen : Window
    {
        public Splashscreen(UserControl control)
        {
            InitializeComponent();

            ContentControl = control;

            Application.Current.Activated += OnAppActivated;
            Application.Current.Deactivated += OnAppDeactivated;
            Application.Current.MainWindow.Activated += OnMainWindowActivated;

        }

        #region Evenement SplashScreen

        private void OnMainWindowActivated(object sender, EventArgs e)
        {
            this.Topmost = true;
        }

        private void OnAppDeactivated(object sender, EventArgs e)
        {
            base.OnDeactivated(e);
            this.Topmost = false;
        }

        private void OnAppActivated(object sender, EventArgs e)
        {
            base.OnActivated(e);
            this.Topmost = true;
        }

        protected override void OnClosed(EventArgs e)
        {
            Application.Current.Activated -= OnAppActivated;
            Application.Current.Deactivated -= OnAppDeactivated;
            if (Application.Current.MainWindow != null)
            Application.Current.MainWindow.Activated -= OnMainWindowActivated;

            this.progress.Value = 0;

            base.OnClosed(e);
        }
        #endregion

        #region Setter Progress

        public void SetProgress(double value)
        {
            this.progress.IsIndeterminate = false;
            this.progress.Value = value;
        }

        public void SetProgress(double value, double maximum)
        {
            this.progress.IsIndeterminate = false;
            this.progress.Value = value;
            this.progress.Maximum = maximum;
        }

        public void SetProgress(string message, double value)
        {
            this.label.Text = message;
            this.progress.IsIndeterminate = false;
            this.progress.Value = value;
        }

        public void SetProgress(string message, double value, double maximum)
        {
            this.label.Text = message;
            this.progress.IsIndeterminate = false;
            this.progress.Value = value;
            this.progress.Maximum = maximum;
        }

        public void Reset()
        {
            this.progress.Value = 0;
            this.progress.Maximum = 0;
        }

        #endregion

        #region Propriétés


        public UserControl ContentControl
        {
            get { return (UserControl)GetValue(ContentControlProperty); }
            set { SetValue(ContentControlProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ContentControl.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ContentControlProperty =
            DependencyProperty.Register("ContentControl", typeof(UserControl), typeof(Splashscreen), new PropertyMetadata(null));

        
        #endregion

    }
}
